package com.wenjie.redHat.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wenjie.redHat.dao.ProductCategoryMapper;
import com.wenjie.redHat.domain.entity.ProductCategoryEntity;
import com.wenjie.redHat.service.ProductCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Slf4j
@Service
public class ProductCategoryImpl extends ServiceImpl<ProductCategoryMapper,ProductCategoryEntity>
        implements ProductCategoryService {
    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    @Override
    public ProductCategoryEntity saveProductCategory(ProductCategoryEntity productCategoryEntity) {
        log.info("=====>"+productCategoryEntity);
        productCategoryMapper.insert(productCategoryEntity);
        return productCategoryEntity;
    }

    @Override
    public String updateProductCategory(ProductCategoryEntity productCategoryEntity) {
        log.info("====>"+productCategoryEntity);
        ProductCategoryEntity productCategory=getOne(new QueryWrapper<ProductCategoryEntity>()
                .eq("id",productCategoryEntity.getId()));
        if (!ObjectUtils.isEmpty(productCategory)){
            this.updateById(productCategoryEntity);
        }
        else {
            return "修改失败";
        }
        return "修改成功";
    }
}
